package com.water.Service.Impl;

import java.sql.SQLException;
import java.util.List;

import com.water.domain.PageBean;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.water.Service.WaterService;
import com.water.dao.WaterDao;
import com.water.dao.impl.WaterDaoImpl;
import com.water.domain.ArticleListBean;
import com.water.domain.ColumnListBean;
import com.water.domain.UserListBean;
import com.water.utils.JDBCUtil02;

public class WaterServiceImpl implements WaterService {
    /* *//**
     * 查询所有用户
     * @return
     * @throws SQLException
     *//*
    @Override
    public List<UserListBean> findAll() throws SQLException {
        // TODO Auto-generated method stub
        WaterDao dao = new WaterDaoImpl();
        List<UserListBean> findAll = dao.findAll();
        return findAll;
    }
*/

    /**
     * 模糊查询
     *
     * @param title
     * @param
     * @return
     * @throws SQLException
     */
    @Override
    public List<ArticleListBean> search(String title, String status) throws SQLException {
        WaterDao dao = new WaterDaoImpl();
        List<ArticleListBean> search = dao.search(title, status);
        return search;
    }

    /**
     * 用户分页查询
     *
     * @param currentPage
     * @return
     * @throws SQLException
     */
    @Override
    public PageBean findUserByPage(int currentPage) throws SQLException {
        //封装分页的该页数据
        PageBean<UserListBean> pageBean = new PageBean<UserListBean>();

        int pageSize = WaterDao.PAGE_SIZE;
        pageBean.setCurrentPage(currentPage); //设置当前页
        pageBean.setPageSize(pageSize); //设置每页显示多少记录

        WaterDao dao = new WaterDaoImpl();
        List<UserListBean> list = dao.findUserByPage(currentPage);
        pageBean.setList(list); //设置这一页的学生数据

        //总的记录数， 总的页数。
        int count = dao.findUserlistCount();
        pageBean.setTotalSize(count); //设置总的记录数
        //200 ， 10 ==20   201 ， 10 = 21   201 % 10 == 0 ?201 / 10 :201 % 10 + 1
        pageBean.setTotalPage(count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1); //总页数
        return pageBean;
    }

    /**
     * 文章分页
     *
     * @param currentPage
     * @return
     * @throws SQLException
     */
    @Override
    public PageBean findArticleByPage(int currentPage) throws SQLException {
        //封装分页的该页数据
        PageBean<ArticleListBean> pageBean = new PageBean<ArticleListBean>();

        int pageSize = WaterDao.PAGE_SIZE;
        pageBean.setCurrentPage(currentPage); //设置当前页
        pageBean.setPageSize(pageSize); //设置每页显示多少记录

        WaterDao dao = new WaterDaoImpl();
        List<ArticleListBean> list = dao.findArticleByPage(currentPage);
        pageBean.setList(list); //设置这一页的学生数据

        //总的记录数， 总的页数。
        int count = dao.findArticleCount();
        pageBean.setTotalSize(count); //设置总的记录数
        //200 ， 10 ==20   201 ， 10 = 21   201 % 10 == 0 ?201 / 10 :201 % 10 + 1
        pageBean.setTotalPage(count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1); //总页数
        return pageBean;
    }

    /**
     * 栏目分页
     *
     * @param currentPage
     * @return
     * @throws SQLException
     */
    @Override
    public PageBean findColumnByPage(int currentPage) throws SQLException {
        //封装分页的该页数据
        PageBean<ColumnListBean> pageBean = new PageBean<ColumnListBean>();

        int pageSize = WaterDao.PAGE_SIZE;
        pageBean.setCurrentPage(currentPage); //设置当前页
        pageBean.setPageSize(pageSize); //设置每页显示多少记录

        WaterDao dao = new WaterDaoImpl();
        List<ColumnListBean> list = dao.findColumnByPage(currentPage);
        pageBean.setList(list); //设置这一页的学生数据

        //总的记录数， 总的页数。
        int count = dao.findColumnCount();
        pageBean.setTotalSize(count); //设置总的记录数
        //200 ， 10 ==20   201 ， 10 = 21   201 % 10 == 0 ?201 / 10 :201 % 10 + 1
        pageBean.setTotalPage(count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1); //总页数
        return pageBean;
    }

    /**
     * 添加栏目
     *
     * @param columnListBean
     * @throws SQLException
     */
    @Override
    public void InsertColumn(ColumnListBean columnListBean) throws SQLException {
        WaterDao dao = new WaterDaoImpl();
        dao.InsertColumn(columnListBean);
    }
    /*

     */
/**
 * 查询所有文章列表
 * @return
 * @throws SQLException
 *//*

    @Override
    public List<ArticleListBean> FindArticleAll() throws SQLException {
        // TODO Auto-generated method stub
        WaterDao dao = new WaterDaoImpl();
        return dao.FindArticleAll();
    }

    */
/**
 * 查询所有栏目
 * @return
 * @throws SQLException
 *//*

    @Override
    public List<ColumnListBean> FindColumnAll() throws SQLException {
        // TODO Auto-generated method stub
        WaterDao dao = new WaterDaoImpl();
        return dao.FindColumnAll();
    }
*/

    /**
     * 删除栏目
     *
     * @param id
     * @throws SQLException
     */
    @Override
    public void DeleteColumn(int id) throws SQLException {
        WaterDao dao = new WaterDaoImpl();
        dao.DeleteColumn(id);
    }

    /**
     * 删除文章
     *
     * @param id
     * @throws SQLException
     */
    @Override
    public void DeleteArticle(int id) throws SQLException {
        WaterDao dao = new WaterDaoImpl();
        dao.DeleteArticle(id);
    }
}
